//
//  UILabel+Category.m
//  ChangGengHospital
//
//  Created by 章松 on 16/11/3.
//  Copyright © 2016年 zhangsong. All rights reserved.
//

#import "UILabel+Category.h"

@implementation UILabel (Category)

+(UILabel*)creatLabel:(CGRect)cg backGroundColor:(UIColor*)bgColor textAligment:(NSInteger)alignment font:(UIFont*)font textColor:(UIColor*)textColor text:(NSString*)text onView:(UIView *)onView
{
    UILabel* label = [[UILabel alloc]initWithFrame:cg];
    
    if (bgColor) {
        label.backgroundColor = bgColor;
    }
    label.userInteractionEnabled = YES;
    label.textAlignment = alignment;
    label.font = font;
    label.textColor = textColor;
    label.text = text;
    [onView addSubview:label];
    return label;
}

+(UILabel*)creatLabel:(CGRect)cg backGroundColor:(UIColor*)bgColor textAligment:(NSInteger)alignment font:(UIFont*)font textColor:(UIColor*)textColor text:(NSString*)text
{
    UILabel* label = [[UILabel alloc]initWithFrame:cg];
    
    if (bgColor) {
        label.backgroundColor = bgColor;
    }
    label.userInteractionEnabled = YES;
    label.textAlignment = alignment;
    label.font = font;
    label.textColor = textColor;
    label.text = text;
    
    return label;
}
-(void)setText:(NSString*)text lineSpacing:(CGFloat)lineSpacing {
    if (!text || lineSpacing < 0.01) {
        self.text = text;
        return;
    }
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:lineSpacing];        //设置行间距
    [paragraphStyle setLineBreakMode:self.lineBreakMode];
    [paragraphStyle setAlignment:self.textAlignment];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    self.attributedText = attributedString;
}




@end
